﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Linq;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;
using MLY.Dal;
using MLY.Bll;
using System.Drawing;
using System.Threading;
using System.Globalization;
using System.Web.UI.HtmlControls;
namespace MLY.LTR
{
    public partial class DisqualifiedMaterial : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (SessParam.IsClient)
                {
                    DisqualifiedMaterialGridView.Columns[1].Visible = false;
                }
                else
                {
                    DisqualifiedMaterialGridView.Columns[0].Visible = false;
                }

                DisqualifiedMaterialDataSource.SelectParameters.Add("OrgId", SessParam.OrganizationId.ToString());
                DisqualifiedMaterialDataSource.SelectParameters.Add("IsClient", SessParam.IsClient ? "1" : "0");
            }
        }

        protected void CancelDisqualify(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
        {
            if (e.CommandArgs.CommandName == "undo")
            {
                using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("SCCover_UndoDisqualify", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("WorkOrderId", SqlDbType.Int);
                    cmd.Parameters.Add("UpdatedBy", SqlDbType.Int);
                    cmd.Parameters["WorkOrderId"].Value = e.CommandArgs.CommandArgument;
                    cmd.Parameters["UpdatedBy"].Value = SessParam.UserId;

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        DisqualifiedMaterialGridView.DataBind();
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }

                }
            }
        
        }
    }
}
